package com.base.config;

import com.base.filter.UserFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.servlet.Filter;

@Configuration
public class WebConfig {
    @Value("${loginPath:/html/page/login}")
    private String loginPath;

    @Autowired
    private RequestMappingHandlerAdapter handlerAdapter;
    /**
     * 配置过滤器
     * @return
     */
    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(userFilter());
        registration.addUrlPatterns("/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("userFilter");
        return registration;
    }

    /**
     * 创建一个bean
     * @return
     */
    @Bean(name = "userFilter")
    public Filter userFilter() {
        return new UserFilter();
    }




//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //配置拦截路径
////        registry.addInterceptor(new SessionInterceptor()).addPathPatterns("/**");
////        registry.addInterceptor(getUserInterceptor()).addPathPatterns("/**")
////                .excludePathPatterns("classpath:/static/**","/css/**","/images/**","/js/**","/lib/**")
////                .excludePathPatterns("**.jpg")
////                .excludePathPatterns("/error")
////                .excludePathPatterns("/html/page/login");//排除登录页面
//    }



//    @Bean
//    public UserInterceptor getUserInterceptor() {
//        return new UserInterceptor();
//    }
//
//    @Bean
//    public SessionInterceptor getSessionInterceptor(){
//        return new SessionInterceptor();
//    }
}
